import LGXCOM from '../common/common.js'
import LXCoord from '../common/struct/coord.js'

import {LGXEnums}  from '../common/sysenum.js'


import globalConst from '../common/globalConst.js'
var global = globalConst.GlobalConst;

import utilfuncs from '../common/tools/utilfuncs.js';
var funcs = utilfuncs.UtilFuncs;

class CMultiModifySvc {
    constructor(datamanger, opsvc) {
        this.m_pDataManager = datamanger;
    }

    translateMultiGraphs(pMultiSelRegion, origOffset, validOffset) {
        var nCount = this.m_pDataManager.getSelectCount();
        if (nCount < 1) {
            return -1;
        }
        var tmp = this.getMultiTransValidOffset(origOffset);
        validOffset.clone(tmp);
        var ret = this.translateMultiGraph(pMultiSelRegion, validOffset);
        return ret;
    }

    //如果批量移动的图形中包含虚拟连接在母线上的虚拟连接点，并且该母线也不在本次框选区域内
    //则移动路径只能沿着母线的走向
    getMultiTransValidOffset(toffset) {
        var validtoffset = new LGXCOM.LGXPoint();
        validtoffset.setVal(toffset.x, toffset.y);
        var forseSetOffset = false;//getMultiTransValidOffsetAlginBus(toffset, validtoffset);
        if (!forseSetOffset) {
            forseSetOffset = false;//getMultiTransValidOffsetAlginBorderLine(toffset, validtoffset);
        }
        if (!forseSetOffset) {
            //尽量尝试跟周边图形对齐或吸附
            // try2AbsorbGraph(toffset,validtoffset,1);
            // try2AbsorbGraph(toffset,validtoffset,2);
        }
        return validtoffset;
    }

    translateMultiGraph(pMultiSelRegion, toffsetGap) {
        if (Math.abs(toffsetGap.x) < global.ZERO_8E && Math.abs(toffsetGap.y) < global.ZERO_8E) {
            return 0;
        }
        var scaling = this.m_pDataManager.getScaling();
        var mapscale = this.m_pDataManager.getMapScale();
        if (pMultiSelRegion) {
            this.m_pDataManager.recordRepaintScope(pMultiSelRegion);
            pMultiSelRegion.translate(toffsetGap, mapscale, true);
            this.m_pDataManager.recordRepaintScope(pMultiSelRegion);
        }

        let selLineLst = [];
        var nCount = this.m_pDataManager.getSelectCount();
        for (let i = 0; i < nCount; i++) {
            var pGraph = this.m_pDataManager.getGraphInSelectList(i);
            if (pGraph && pGraph.m_graphType == LGXEnums.LGXGraphType.LineGraph_type){
                selLineLst.push(pGraph);
            }
        }

        for (let i = 0; i < nCount; i++) {
            var pGraph = this.m_pDataManager.getGraphInSelectList(i);
            var pBelongDevGraph = null;//pGraph.getBelongDevGraph();
            if (pBelongDevGraph) {
                if (this.m_pDataManager.getIndexInSelectList(pBelongDevGraph) >= 0) {
                    //如果标签所属设备图形自身已经在框选平移队列中，则标签图形不需要调用移动函数，其所属设备图形移动过程中会把
                    //其所包含的标签图形一起移动
                    continue;
                }
            }

            this.m_pDataManager.recordRepaintScope(pGraph);
            pGraph.translate(toffsetGap, mapscale, true,selLineLst);
            this.m_pDataManager.recordRepaintScope(pGraph);
        }

        nCount = this.m_pDataManager.getBorderCount();
        for (let i = 0; i < nCount; i++) {
            pGraph = this.m_pDataManager.getGraphInBorderList(i);
            //resetBoderLineConnKind(pGraph);
            var kind = pGraph.getSelKind();
            if (kind > 0 && pGraph.m_graphType == LGXEnums.LGXGraphType.LineGraph_type) {
                m_pDataManager.remindModifingGraphScope(pGraph);
                //lineDevGraph.translateEndPoint(toffsetGap, kind, scaling,mapscale);
                this.m_pDataManager.remindModifingGraphScope(pGraph);
            }
        }

        if (this.m_pDataManager.getTopoManager() != null) {
            //this.m_pDataManager.getTopoManager().ModifyGap(toffsetGap);
        }
        return 0;
    }
}

export default { CMultiModifySvc }